import messageApi from 'api/message'

// state
let state = {
  list: {}, // 获取系统消息
  // markMsg: {},
  unReadMsg: {}, // 获取未读消息总条数
  unReadOrgMsg: {} // 获取组织未读信息总条数
}

// getters
const getters = {
  message_list: state => state.list,
  message_mark_msg: state => state.markMsg,
  message_unread: state => state.unReadMsg,
  message_organize_unread: state => state.unReadOrgMsg
}

// actions
const actions = {
  message_list ({ commit, state }, params) {
    messageApi.list(params).then((json) => {
      commit('MESSAGE_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  // message_mark_msg ({ commit, state }, params) {
  //   messageApi.markMsg(params).then((json) => {
  //     commit('MESSAGE_MARK_MSG', {
  //       params: params,
  //       data: json.data
  //     })
  //   })
  // },
  message_unread ({ commit, state }, params) {
    messageApi.unReadMsg(params).then((json) => {
      commit('MESSAGE_UNREAD', {
        params: params,
        data: json.data
      })
    })
  },
  message_organize_unread ({ commit, state }, params) {
    messageApi.unReadOrgMsg(params).then((json) => {
      commit('MESSAGE_ORGANIZE_UNREAD', {
        params: params,
        data: json.data
      })
    })
  }
}
// mutations
const mutations = {
  MESSAGE_LIST (state, { data, params }) {
    state.list = data
  },
  // MESSAGE_MARK_MSG (state, { data, params }) {
  //   state.markMsg = data
  // },
  MESSAGE_UNREAD (state, { data, params }) {
    state.unReadMsg = data
  },
  MESSAGE_ORGANIZE_UNREAD (state, params) {
    state.unReadOrgMsg = params
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
